2015-08-15DB.txt 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. if exists(select 1 from sysobjects where id=object_id('fn_GetOrderArrears') and objectproperty(id,'IsInlineFunction')=0)
  2. BEGIN
  3. DROP function [dbo].fn_GetOrderArrears
  4. END
  5. GO
  6. IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[fn_GetOrderArrears]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
  7. BEGIN
  8. execute dbo.sp_executesql @statement = N'--欠款
  9. CREATE function [dbo].[fn_GetOrderArrears](@FID varchar(800))
  10. /******
  11. 分类字符转换
  12. 创建人:滕工
  13. 创建日期:2014-6-23 14:55:29
  14. 修改人:
  15. 修改说明:
  16. 修改日期:
  17. ******/
  18. Returns varchar(800)
  19. As
  20. Begin
  21. Declare @Arrears decimal(10, 2)
  22. Declare @Aoumnt decimal(10, 2)
  23. set @Arrears = (select Ord_SeriesPrice from tb_ErpOrder where Ord_Number = @FID)
  24. set @Aoumnt = (Select sum(Plu_Amount) as Plu_Amount from tb_ErpPlusPickItems where Plu_OrdNumber = @FID)
  25. if @Aoumnt is not null
  26. begin
  27. set @Arrears = @Arrears + @Aoumnt
  28. end
  29. set @Aoumnt = 0
  30. set @Aoumnt = (select sum(Pay_AmountOf) from dbo.tb_ErpPayment where Pay_OrdNumber =@FID)
  31. if @Aoumnt is not null
  32. begin
  33. set @Arrears = @Arrears - @Aoumnt
  34. end
  35. Return @Arrears
  36. End
  37. '
  38. END
  39. if exists(select 1 from sysobjects where id=object_id('fn_GetOrderReceivable') and objectproperty(id,'IsInlineFunction')=0)
  40. BEGIN
  41. DROP function [dbo].fn_GetOrderReceivable
  42. END
  43. GO
  44. IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[fn_GetOrderReceivable]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
  45. BEGIN
  46. execute dbo.sp_executesql @statement = N'
  47. --应收帐款
  48. CREATE function [dbo].[fn_GetOrderReceivable](@FID varchar(800))
  49. /******
  50. 分类字符转换
  51. 创建人:滕工
  52. 创建日期:2014-6-23 14:55:29
  53. 修改人:
  54. 修改说明:
  55. 修改日期:
  56. ******/
  57. Returns varchar(800)
  58. As
  59. Begin
  60. Declare @Arrears decimal(10, 2)
  61. Declare @Aoumnt decimal(10, 2)
  62. set @Arrears = (select Ord_SeriesPrice from tb_ErpOrder where Ord_Number = @FID)
  63. set @Aoumnt = (Select sum(Plu_Amount) as Plu_Amount from tb_ErpPlusPickItems where Plu_OrdNumber = @FID)
  64. if @Aoumnt is not null
  65. begin
  66. set @Arrears = @Arrears + @Aoumnt
  67. end
  68. Return @Arrears
  69. End
  70. '
  71. END
  72. GO
  73. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vwp_GetLastClientTrackRecord')
  74. BEGIN
  75. DROP VIEW [dbo].Vwp_GetLastClientTrackRecord
  76. END
  77. GO
  78. SET ANSI_NULLS ON
  79. GO
  80. SET QUOTED_IDENTIFIER ON
  81. GO
  82. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[Vwp_GetLastClientTrackRecord]'))
  83. EXEC dbo.sp_executesql @statement = N'
  84. CREATE VIEW [dbo].[Vwp_GetLastClientTrackRecord]
  85. AS
  86. SELECT id, TR_CustomerGroupID, TR_CustomerID, TR_TraceWay, TR_TraceType, TR_SpecificMatters,
  87. TR_Communicationstatus, TR_TraceDetailedly, TR_CallRecording, TR_Remark, TR_TraceDateTime,
  88. TR_TraceTimeLength, TR_TracePersonID, TR_CreateDateTime, TR_UpdateDateName
  89. FROM dbo.tb_ErpCustomersTrackRecord
  90. WHERE (id IN
  91. (SELECT MAX(id) AS Expr1
  92. FROM dbo.tb_ErpCustomersTrackRecord AS tb_ErpCustomersTrackRecord_1
  93. GROUP BY TR_CustomerGroupID,TR_TraceType))
  94. '
  95. GO